<?php

namespace App\Http\Models\Student;

use Illuminate\Foundation\Http\FormRequest;

class StudentFrom extends FormRequest
{

    public $forRequestStatus = 0;

    public function authorize()
    {
        if ($this->all()['status']) {
            $this->forRequestStatus = 1; //团课验证。如果不是1  则是 私教验证
        }
        return true;
    }

    public function rules()
    {
        //验证团课
        if ($this->forRequestStatus == 0) {
            $rules = [
                'member_number' => 'required|integer',
                'amount'        => 'required|integer',
            ];
            if ($this->all()['vips'] == 1) {
                $rules['begin_time'] = 'required';
                $rules['end_time'] = 'required';
            } else {
                $rules['league'] = 'required';
            }
            return $rules;
        }

        return [
            'member_number' => 'required|integer',
            'sijiao'        => 'required',
            'amount'        => 'required|integer'
        ];
    }

    public function messages()
    {
        if ($this->forRequestStatus == 0) {
            $message = [
                'member_number.required' => "请选择次数",
                'amount.required'        => "金额不能为空（刷新页面重新选择）",
                'amount.integer'         => '金额格式错误请输入数字（刷新页面重新选择）'
            ];
            if ($this->all()['vips'] == 1) {
                $message['begin_time.required'] = '会员开始时间不能为空';
                $message['end_time.required'] = '会员结束时间不能为空';
            } else {
                $message['league.required'] = '团课课程不能为空';
            }
            return $message;
        }
        return [
            'member_number.required' => "请选择次数",
            'sijiao.required'        => '私教不能为空 (刷新页面请选择)',
            'amount.required'        => "金额不能为空（刷新页面重新选择）",
            'amount.integer'         => '金额格式错误请输入数字（刷新页面重新选择）'
        ];
    }

}
